package com.eurake.seckill.rabbitmq;

import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageProperties;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class MQSender {
    /*@Autowired
    private RabbitTemplate rabbitTemplate;

    public void send(Object message) {
        log.info("send message:{}", message);
        rabbitTemplate.convertAndSend("fanoutExchange","",message);
    }

    public void send01(Object message) {
        log.info("send message:{}", message);
        rabbitTemplate.convertAndSend("directExchange","direct.red",message);
    }

    public void send02(Object message) {
        log.info("send message:{}", message);
        rabbitTemplate.convertAndSend("directExchange","direct.green",message);
    }

    public void send03(Object message) {
        log.info("send message:{}", message);
        rabbitTemplate.convertAndSend("topicExchange","queue.red.message",message);
    }

    public void send04(Object message) {
        log.info("send message:{}", message);
        rabbitTemplate.convertAndSend("topicExchange","message.queue.green.abc",message);
    }

    public void send05(Object message) {
        log.info("send message:{}", message);
        MessageProperties messageProperties = new MessageProperties();
        messageProperties.setHeader("color","red");
        messageProperties.setHeader("speed","fast");
        Message message1 = new Message(message.toString().getBytes(),messageProperties);
        rabbitTemplate.convertAndSend("HeadersExchange","",message1);
    }

    public void send06(Object message) {
        log.info("send message:{}", message);
        MessageProperties messageProperties = new MessageProperties();
        messageProperties.setHeader("color","red");
        Message message1 = new Message(message.toString().getBytes(),messageProperties);
        rabbitTemplate.convertAndSend("HeadersExchange","",message1);
    }*/

    @Resource
    private RabbitTemplate rabbitTemplate;

    public void sendSeckillMsg(String message) {
        log.info("send seckill msg:{}", message);
        rabbitTemplate.convertAndSend("seckillExchange","seckill.1",message);
    }
}
